package com.woniu.service.impl;

import com.sun.org.apache.xpath.internal.operations.Or;
import com.woniu.pojo.Course;
import com.woniu.pojo.Order;
import com.woniu.mapper.OrderMapper;
import com.woniu.service.ICourseService;
import com.woniu.service.IOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author xiaoruan
 * @since 2023-03-22
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    ICourseService courseService;

    @Resource
    OrderMapper orderMapper;
    @Override
    public Order saveOrder(String courseId,String userId) {

        Course course = courseService.getById(courseId);

        Order order = new Order();
        order.setCourseId(courseId);
        order.setPrice(course.getPrice());
        order.setOrderTime(new Date());
        order.setStatus("1");
//        order.setUserId(userId); //这里先不写，因为登录那边还没有做，session里面没有数据
        order.setUserId("1080736474267144193");

        orderMapper.insert(order);

        return order;
    }
}
